#region Using

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using BlogEngine.Core;
using BlogEngine.Core.Provider.Interfaces;

#endregion

namespace BlogEngine.Core.Provider.MSSQL
{
	/// <summary>
	/// A storage provider for BlogEngine that uses XML files.
	/// <remarks>
	/// To build another provider, you can just copy and modify
	/// this one. Then add it to the web.config's BlogEngine section.
	/// </remarks>
	/// </summary>
	public class Provider : BlogProviderBase
	{
		private static string _DatabaseName = "BlogEngine";

		/// <summary>
		/// Gets the name of the database.
		/// </summary>
		/// <value>The name of the database.</value>
		public static string DatabaseName
		{
			get
			{
				return _DatabaseName;
			}
		}
		/// <summary>
		/// Initializes the provider
		/// </summary>
		/// <param name="name">Configuration name</param>
		/// <param name="config">Configuration settings</param>
		public override void Initialize(string name, NameValueCollection config)
		{
			if (config == null)
			{
				throw new ArgumentNullException("config");
			}

			if (String.IsNullOrEmpty(name))
			{
				name = "MSSQLBlogProvider";
			}

			if (String.IsNullOrEmpty(config["description"]))
			{
				config.Remove("description");
				config.Add("description", "MSSQL Blog Provider");
			}

			base.Initialize(name, config);

			if (!string.IsNullOrEmpty(config["connectionStringName"]))
			{
				_DatabaseName = config["connectionStringName"];
			}

			config.Remove("connectionStringName");
		}

		public Provider()
		{
			// TODO: use reflection to find and register the interfaces with their concrete implementations
//			Register(typeof(IPhotos), new CIPhotos());
//			Register(typeof(IAlbums), new CIAlbums());
//			Register(typeof(IPhotoEffects), new CIPhotoEffects());
			Register(typeof(IPosts), new CIPosts());
			Register(typeof(ICategories), new CICategories());
			Register(typeof(IPages), new CIPages());
			Register(typeof(ILinks), new CILinks());
			Register(typeof(IPingServices), new CIPingServices());
			Register(typeof(ISettings), new CISettings());
//			Register(typeof(IPhotoStorage), new CIPhotoStorage());
			//Register(typeof(IExtensionSettings), new CIExtensionSettings());
		}
	}
}
